package spbgpu.ftf.pobiim.logic;

import java.util.SortedMap;
import java.util.TreeMap;

public class QuadraticEq implements Equation {

	public SortedMap<Double, Double> calculateEquation() {
		SortedMap<Double, Double> result = new TreeMap<Double, Double>();
		Double startAngle = 45d;
		Double sinAngleOfIncidence = Math.sin(startAngle * Math.PI / 180);
		Double sinAngleOfRefraction;
		Double nInsidence = 1d;
		Double nRefracrion;
		Double x = 0d;
		for (Double y = 0d; y < 10; y=y+0.01) {
			nInsidence = 1 + Math.exp((-1) * ((y-3) * (y-3)) / 2);
			nRefracrion = 1 + Math.exp((-1) * ((y + 0.01 - 3) * (y + 0.01 - 3)) / 2);
			sinAngleOfRefraction = nInsidence * sinAngleOfIncidence
					/ nRefracrion;

			Double cosAngleOfRefraction = Math.sqrt(1 - sinAngleOfRefraction
					* sinAngleOfRefraction);

			x = Math.sqrt(y * y / (cosAngleOfRefraction * cosAngleOfRefraction)
					- y * y);
			System.out.println(nInsidence + " " + nRefracrion + " " + y);
			result.put(x, y);
			sinAngleOfIncidence = sinAngleOfRefraction;

		}
		return result;

	}

	@Override
	public String getLabel() {
		return "n = 1 + n0*exp[((y-y0)^2)/2]";
	}

	@Override
	public String getName() {
		return "exp";
	}

}